package com.yida.gwj.expend.outside.exception;

import java.sql.SQLException;

import org.apache.commons.validator.ValidatorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yida.common.core.web.domain.AjaxResult;

/**
 * 维修基金异常处理拦截
 *
 * @author liangp
 * @date 2023/02/09
 */
@Deprecated
// @ControllerAdvice
public class MaintenanceFundsExceptionHandler {

    private final Logger log = LoggerFactory.getLogger(MaintenanceFundsExceptionHandler.class);

    @ExceptionHandler(MaintenanceFundsBusinessException.class)
    @ResponseBody
    public AjaxResult maintenanceFundsBusinessException(MaintenanceFundsBusinessException e) {
        if (log.isDebugEnabled()) {
            log.debug("公维金资金申请业务异常 ex -> 编码: [{}], 内容: [{}]", e);
        }
        return AjaxResult.error(e.getMaintenanceFundsErrorEnum().getMsg());
    }

    @ExceptionHandler(MaintenanceFundsBusinessWebException.class)
    @ResponseBody
    public AjaxResult maintenanceFundsBusinessException(MaintenanceFundsBusinessWebException e) {
        log.info("公维金资金申请业务异常 ex -> {}", e.getMessage());
        return AjaxResult.error(e.getMessage());
    }

    @ExceptionHandler(ValidatorException.class)
    @ResponseBody
    public AjaxResult validatorException(ValidatorException e) {
        if (log.isDebugEnabled()) {
            log.debug("参数校验异常 ex -> {}", e.getMessage());
        }
        return AjaxResult.error(e.getMessage());
    }

    @ExceptionHandler(DataAccessException.class)
    @ResponseBody
    public AjaxResult sqlException(SQLException e) {
        log.error("sql异常信息 ex -> {}", e.getMessage(), e);
        return AjaxResult.success(e.getMessage());
    }

}
